home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.lib;
-
- import sub_arctic.input.snap_targetable;
- import sub_arctic.input.snap_draggable;
- import sub_arctic.input.snap_drag_agent;
- import sub_arctic.input.int_holder;
- import sub_arctic.input.event;
-
- import java.awt.Image;
- import java.awt.Point;
-
- /**
- * This Class implements a point snap target. The target point is defined to
- * lie in the center of the object. It does no drawing nor does it limit the
- * class of drag objects that snap to it, or do anything when the snap occurs
- * (all these additional behaviors would normally be added in a subclass).
- * See the documentation in the snap-drag agent for full details of how
- * snapping works.
- *
- * @see sub_arctic.input.snap_drag_agent
- * @author Scott Hudson
- */
- public class point_snap_target
- extends base_interactor implements snap_targetable {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Constructor.
- * @param int x the x coordinate of the snap target point.
- * @param int y the y coordinate of the snap target point.
- */
- public point_snap_target(int x, int y)
- {
- super(x,y, 1,1);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- /* snap_targetable methods */
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
-
- /** Determine if the given point (in local coordinates) is close enough
- * to snap to the point (and return the square of its distance, and
- * the point snapped to). This is a geometric test only. It reports
- * a snap if the square of the distance to the point is less than or equal
- * to snap_drag_agent.snap_dist2(). The object return_dist2 object is
- * modified so that it contains the square of the distance from the drag
- * point to the target point. The return_snap_pt object is modified to
- * return the position of the target point.
- *
- * @param pt the point being tested (in local coordinates).
- * @param return_dist2 modified to contain the square of the distance
- * to the point.
- * @param return_snap_pt modified to contain the snap target point location
- * in local coordinates (i.e., 0,0).
- * @return boolean indicating whether the snap is geometrically accepted.
- */
- public boolean point_snaps(
- Point pt,
- int_holder return_dist2,
- Point return_snap_pt)
- {
- int dist, tx, ty;
-
- /* target point is at our center */
- tx = w()/2;
- ty = h()/2;
-
- /* compute square of distance from target to drag point */
- dist = (tx-pt.x)*(tx-pt.x) + (ty-pt.y)*(ty-pt.y);
-
- /* do we snap? */
- if (dist <= snap_drag_agent.snap_dist2())
- {
- /* return our values + success */
- return_dist2.value = dist;
- return_snap_pt.x = tx;
- return_snap_pt.y = ty;
-
- return true;
- }
- else
- return false;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Determine if a geometrically accepted snap should be semantically
- * accepted. In this case we accept all snaps.
- *
- * @param pt the pre-snap location of the feature point being
- * tested.
- * @param drag_obj the drag object being tested.
- * @param feature_pt_indx the index of the feature point (within drag_obj)
- * being tested.
- * @return whether the snap is acceptable.
- */
- public boolean snap_from_ok(
- Point pt,
- snap_draggable drag_obj,
- int feature_pt_indx)
- {
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Determine if a geometrically accepted snap which has been semantically
- * rejected (by snap_from_obj()) should provide anti-snap feedback.
- * In this case we never provide anti-snap feedback.
- *
- * @param pt the pre-snap location of the feature point being
- * tested.
- * @param drag_obj the drag object being tested.
- * @param feature_pt_indx the index of the feature point (within drag_obj)
- * being tested.
- * @return null for no anti-snap. if anti-snap feedback is desired a
- * non-null object is returned (which is later passed to various anti-snap
- * routines in the protocol).
- */
- public Object anti_snap_from_ok(
- Point pt,
- snap_draggable drag_obj,
- int feature_pt_indx)
- {
- return null;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Do the feedback corresponding to a snap from the given drag object.
- * This class does no feedback, so this is accepted but ignored.
- *
- * @param event evt the event that "caused the snap".
- * @param Point orig_pt the point the dragged object would nominally
- * be at.
- * @param Point snap_pt the point the dragged object snaps to.
- * @param snap_draggable drag_obj the dragged object.
- * @param int feature_pt_indx the feature point within dragged
- * object that we are snapping with.
- * @param Object user_info the information that was associated
- * with the dragged object when it
- * requested snap-drag focus.
- */
- public boolean snap_from(
- event evt,
- Point orig_pt,
- Point snap_pt,
- snap_draggable drag_obj,
- int feature_pt_indx,
- Object user_info)
- {
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Do feedback while a snap is active.
- *
- * @param event evt the event that "caused the snap".
- * @param Point orig_pt the point the dragged object would nominally
- * be at.
- * @param Point snap_pt the point the dragged object snaps to.
- * @param snap_draggable drag_obj the dragged object.
- * @param int feature_pt_indx the feature point within dragged
- * object that we are snapping with.
- * @param Object user_info the information that was associated
- * with the dragged object when it
- * requested snap-drag focus.
- */
- public boolean snap_feedback(
- event evt,
- Point orig_pt,
- Point snap_pt,
- snap_draggable drag_obj,
- int feature_pt_indx,
- Object user_info)
- {
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Remove feedback for a snap that is now being broken. This class does
- * no feedback, so this is accepted but ignored.
- *
- * @param event evt the event that "caused the snap".
- * @param Point orig_pt the point the dragged object would nominally
- * be at.
- * @param Point snap_pt the point the dragged object snaps to.
- * @param snap_draggable drag_obj the dragged object.
- * @param int feature_pt_indx the feature point within dragged
- * object that we are snapping with.
- * @param Object user_info the information that was associated
- * with the dragged object when it
- * requested snap-drag focus.
- */
- public boolean unsnap_from(
- event evt,
- Point orig_pt,
- Point snap_pt,
- snap_draggable drag_obj,
- int feature_pt_indx,
- Object user_info)
- {
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Do anti-snap feedback corresponding to an anti-snap from the given
- * drag object. This class does not do anti-snaps, so this is accepted
- * but ignored.
- *
- * @param event evt the event that "caused the anti-snap".
- * @param Point orig_pt the point the dragged object would nominally
- * be at.
- * @param Point snap_pt the point the dragged object anti-snaps to.
- * @param snap_draggable drag_obj the dragged object.
- * @param int feature_pt_indx the feature point within dragged
- * object that we are anti-snapping
- * with.
- * @param Object user_info the information that was associated
- * with the dragged object when it
- * requested snap-drag focus.
- */
- public boolean anti_snap_from(
- event evt,
- Point orig_pt,
- Point snap_pt,
- snap_draggable drag_obj,
- int feature_pt_indx,
- Object anti_snap_info,
- Object user_info)
- {
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /*
- * Do feedback while an anti-snap is in place.
- *
- * @param event evt the event that "caused the anti-snap".
- * @param Point orig_pt the point the dragged object would nominally
- * be at.
- * @param Point snap_pt the point the dragged object anti-snaps to.
- * @param snap_draggable drag_obj the dragged object.
- * @param int feature_pt_indx the feature point within dragged
- * object that we are anti-snapping
- * with.
- * @param Object user_info the information that was associated
- * with the dragged object when it
- * requested snap-drag focus.
- */
- public boolean anti_snap_feedback(
- event evt,
- Point orig_pt,
- Point snap_pt,
- snap_draggable drag_obj,
- int feature_pt_indx,
- Object anti_snap_info,
- Object user_info)
- {
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Remove anti-snap feedback for an anti-snap that is now being broken.
- * This class does not do anti-snaps, so this is accepted but ignored.
- *
- * @param event evt the event that "caused the anti-snap".
- * @param Point orig_pt the point the dragged object would nominally
- * be at.
- * @param Point snap_pt the point the dragged object anti-snaps to.
- * @param snap_draggable drag_obj the dragged object.
- * @param int feature_pt_indx the feature point within dragged
- * object that we are anti-snapping
- * with.
- * @param Object user_info the information that was associated
- * with the dragged object when it
- * requested snap-drag focus.
- */
- public boolean unanti_snap_from(
- event evt,
- Point orig_pt,
- Point snap_pt,
- snap_draggable drag_obj,
- int feature_pt_indx,
- Object anti_snap_info,
- Object user_info)
- {
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-